<?php

/**
*
* @package DND Charlist
* @version $Id: dnd_char.php$
* @copyright (c) 2010 Stephan "MOTU" König
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

// Benötigte Dateien und Variablen von phpBB
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Session auslesen und Benutzer-Informationen laden
$user->session_begin();
$user->setup();
$auth->acl($user->data);

// Initial var setup
$user_id	= request_var('u', ANONYMOUS);
$username	= request_var('un', '', true);
$char_data = array();
$chars = array();
$i = 0;

/*
* Inhaltsbereich
*/

// Header und Titel der Seite
page_header('DnD Char List');

// Angabe eurer Content-Seite
$template->set_filenames(array(
	'body' => 'dnd_char.html')
);

if ($user->data['user_id'] == ANONYMOUS)
{
	// Code, wenn Benutzer nicht angemeldet ist
	login_box();
}
else
{
	// Code, wenn Benutzer angemeldet ist
	// Alle Chars aus table dnd_chars laden
	if(ISSET($_GET['CHAR_ID']) ? intval($_GET['CHAR_ID']) : intval($_GET['CHAR_ID']))
	{
		$char_id = intval($_GET['CHAR_ID']);
		
		$dndList->getList($char_id,0);
		$char_data = $dndList->getChars();
		print_r($char_data);
// 		$sql_array = array(
// 			'SELECT'	=> 'c.*, r.name as race, g.name as grp,a.name as alignment,d.name as deity,s.name as size',
// 		
// 			'FROM'		=> array(
// 				DND_CHAR		=> 'c'
// 			),
// 		
// 			'LEFT_JOIN'	=> array(
// 				array(
// 					'FROM'	=> array(DND_RACE => 'r'),
// 					'ON'	=> 'r.id = c.race_id'
// 				),
// 				array(
// 					'FROM'	=> array(DND_GROUP => 'g'),
// 					'ON'	=> 'g.id = c.group_id'
// 				),
// 				array(
// 					'FROM'	=> array(DND_ALIGNMENT => 'a'),
// 					'ON'	=> 'a.id = c.alignment_id'
// 				),
// 				array(
// 					'FROM'	=> array(DND_DEITY => 'd'),
// 					'ON'	=> 'd.id = c.deity_id'
// 				),
// 				array(
// 					'FROM'	=> array(DND_SIZE => 's'),
// 					'ON'	=> 's.id = c.size_id'
// 				)
// 			),
// 		
// 			'WHERE'	=> 'c.id = ' . $char_id,
// 		);
// 	
// 		$sql = $db->sql_build_query('SELECT', $sql_array);
// 	
// 		$result = $db->sql_query($sql);
// 		$char_data = $db->sql_fetchrow($result);
// 		$db->sql_freeresult($result);
	}
	else
	{
		echo "Some shit happens...";
	}
	
	
	/*
	$template->assign_vars(array(
		'CHAR_NAME'	=> $chars,
	));
	*/
	$template->assign_vars(array(
		'CHAR_NAME'		=> $char_data['name'],
		'RACE'			=> $char_data['race'],
		'GROUP'			=> $char_data['grp'],
		'INFO'			=> $char_data['char_info'],
		'CHAR_ID'		=> $char_data['id'],
		'DEITY'			=> $char_data['deity'],
	));

}

// Footer
page_footer();

?>